﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ORMAC.Attributes;
using System.Linq.Expressions;

namespace ORMAC.UnitTest
{
    public class Repository
    {
        private string m_ConnectionString { get; set; }
        public Repository(string cnn)
        {
            m_ConnectionString = cnn;
        }
        [StoredProcedure(Name="ListCustomers")]
        public List<Person> GetCustomerList(){
            IReader orm = new OReader();
            orm.SetConnectionString(m_ConnectionString);
            var res = orm.Exceute<Person>(this,"GetCustomerList");
            return res;
        }
        [StoredProcedure(Name = "ListInvoices")]
        public List<Invoice> GetInvoices()
        {
            IReader orm = new OReader();
            orm.SetConnectionString(m_ConnectionString);
            var res = orm.Exceute<Invoice>(this, "GetInvoices");
            return res;
        }
        [SPParam(DBName="@PersonID")]
        [StoredProcedure(Name = "SelectCustomer")]
        public List<Person> SelectCustomer(int ID)
        {
            IReader orm = new OReader();
            orm.SetConnectionString(m_ConnectionString);
            var res = orm.Exceute<Person>(this, "SelectCustomer",ID);
            return res;
        }
        [SPParam(DBName = "@InvoiceID")]
        [StoredProcedure(Name = "GetTotalInvoice")]
        public decimal GetTotalInvoice(int ID)
        {
            IReader orm = new OReader();
            orm.SetConnectionString(m_ConnectionString);
            var res = orm.ExceuteScalar<decimal>(this, "GetTotalInvoice", ID);
            return res;
        }
        [SPParam(DBName = "@InvoiceID")]
        [StoredProcedure(Name = "GetTotalInvoice2")]
        public decimal GetTotalInvoice2(int ID)
        {
            IReader orm = new OReader();
            orm.SetConnectionString(m_ConnectionString);
            var res = orm.ExceuteScalar<decimal>(this, "GetTotalInvoice", ID);
            return res;
        }
    }
}
